<!DOCTYPE html>
<html>
<head>
<title>商品管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<#include "../../../../include/resources.html">
<script type="text/javascript">
    var dataGrid;
    var winWidth =  800;
    var winHeight = 500;
    var addTitle = "添加商品";
	var addUrl =  "/modules/user/score/goods/append.html";
	
    var verifyTitle = "商品审核";
    var verifyUrl =  "/modules/user/score/goods/verify.html";
    var verifyWinParmeters = "'{0}','"+verifyTitle+"',920,650,'"+verifyUrl+"'";
    
	var editSurveyTitle = "编辑商品信息";
    var editSurveyUrl =  "/modules/user/score/goods/modify.html";
    var editSurveyWinParmeters = "'{0}','"+editSurveyTitle+"',920,650,'"+editSurveyUrl+"'";
	
	var shelvesTitle = "商品上下架";
    var shelvesUrl =  "/modules/user/score/goods/shelves.html";
    var shelvesWinParmeters = "'{0}','"+shelvesTitle+"',920,650,'"+shelvesUrl+"'";
    
    $(function() {
        dataGrid = $('#dataGrid').datagrid({
        	url : 'list.html',
			fit : true,
			fitColumns : true,
			border : false,
			pagination : true,
			idField : 'id',
			pageSize : pageSize,
			pageNums :1,
			pageList : pageList,
			sortName : 'id',
			sortOrder : 'asc',
			checkOnSelect : false,
			selectOnCheck : false,
			nowrap : false,
			singleSelect:true,
            columns : [ [
				{ field: 'id', title: '编号', width: 50, sortable:false },              
				{ field: 'name', title: '商品名', width: 150, sortable:false },
				{ field: 'categoryName', title: '商品类别', width: 100, sortable:false },
				{ field: 'score', title: '兑换积分', width: 90, sortable:false },
				{ field: 'cost', title: '商城售价(元)', width: 100, sortable:false },
				{ field: 'marketPrice', title: '市场价(元)', width: 90, sortable:false },
				{ field: 'store', title: '商品库存', width: 90, sortable:false },
				{ field: 'freezeStore', title: '冻结库存', width: 100, sortable:false },
				{ field: 'sellAcount', title: '销量', width: 80, sortable:false },
				{ field: 'isVirtual', title: '虚拟商品', width: 90, sortable:false,
                	formatter: function(value,row,index){
                		if(value == 0){
                			return "否";
                		} else if(value == 1){
                			return "是";
                		}
                  	}
             	},
             	<#if need_verify>
					{ field: 'status', title: '状态', width: 80, sortable:false,
	       				formatter: function(value,row,index){
			           		if(value == 0){
			           			return "待审核";
			           		}else if(value == 1){
			           			return "审核通过";
			           		}else if(value == -1){
			           			return "审核不通过";
			           		}
	         			} 
	         		},
	         	</#if>
                { field: 'type', title: '类型', width: 60, sortable:false,
                	formatter: function(value,row,index){
                		if(value == 0){
                			return "待上架";
                		}else if(value == 1){
                			return "已上架";
                		}else if(value == -1){
                			return "已下架";
                		}
                  	} 
             	},
				
				{ field : 'showInfo',
	                title : '其他信息',
	                width :75,
	                align:'center',
	                fixed:true,
	                formatter : function(value, row, index) {
						var content = '<a href="javascript:void(0);" class="j-showInfo">查看<i class="iconfont">&#xe639;</i></a>'
							+ '<div class="showInfoSingleDiv">'
							+ '<div class="showInfo">'
							+ '<em></em><h2>商品信息</h2>'
							+ '<ul>'
							+ '<li>'
	                		+ '<span>添加时间：</span>'
							+ getLocalTime(row.addTime,4)
							+ '</li>';
						if(row.status == 1 && row.type == 1){
							content += '<li>'
	                		+ '<span>上架时间：</span>'
							+ getLocalTime(row.shelvesTime,4)
							+ '</li>'
						}
							content += '<li>'
	                		+ '<span>备注：</span>'
							+ row.remark
							+ '</li>'
							+ '</ul></div></div>';
						return content;
					}
				},
				
                { field : 'action',
                    title : '操作',
                    width : 75,
                    fixed : true,
                    formatter : function(value, row, index) {
                    	var status = row.status;
                    	var type = row.type;
                        var str = '';
                        <#if need_verify>
	                        if (status == 0) {
	                        	str += '<dl>';
	                        	str += '<dt><a href="javascript:void(0);" onclick="$.fn.dataGridOptions.editFun('+row.id+',editSurveyTitle,winWidth,winHeight,editSurveyUrl);" title="编辑商品">编辑</a><i class="iconfont">&#xe639;</i></dt>' ;
	                        	str += '<dd><a href="javascript:void(0);" onclick="$.fn.dataGridOptions.editFun('+row.id+',verifyTitle,winWidth,winHeight,verifyUrl);" title="审核">审核</a></dd>';
	                        	str +=  '</dl>'
			                } else if(status == 1){
				                if(type == 0 || type == -1){
				                	str += '<a href="javascript:void(0);" onclick="$.fn.dataGridOptions.editFun('+row.id+',shelvesTitle,winWidth,winHeight,shelvesUrl);" title="上架">&nbsp;&nbsp;&nbsp;上架</a>';
				                }else if(type == 1){
				                	str += '<a href="javascript:void(0);" onclick="$.fn.dataGridOptions.editFun('+row.id+',shelvesTitle,winWidth,winHeight,shelvesUrl);" title="下架">&nbsp;&nbsp;&nbsp;下架</a>';
				                }
			                } else if(status == -1){
			                	str += '<a href="javascript:void(0);" onclick="$.fn.dataGridOptions.editFun('+row.id+',editSurveyTitle,winWidth,winHeight,editSurveyUrl);" title="编辑商品">&nbsp;&nbsp;&nbsp;编辑</a>' ;
				            }
                        <#else>
	                        str += '<dl>';
	                        str += '<dt><a href="javascript:void(0);" onclick="$.fn.dataGridOptions.editFun('+row.id+',editSurveyTitle,winWidth,winHeight,editSurveyUrl);" title="编辑商品">编辑</a><i class="iconfont">&#xe639;</i></dt>' ;
	                        if(type == 0 || type == -1){
	                        	str += '<dd><a href="javascript:void(0);" onclick="$.fn.dataGridOptions.editFun('+row.id+',shelvesTitle,winWidth,winHeight,shelvesUrl);" title="上架">上架</a></dd>';
			                } else if(type == 1){
			                	str += '<dd><a href="javascript:void(0);" onclick="$.fn.dataGridOptions.editFun('+row.id+',shelvesTitle,winWidth,winHeight,shelvesUrl);" title="下架">下架</a></dd>';
			                }
	                        str += '</dl>'
                        </#if>
                        return str;
                    }
                } 
            ] ],
            toolbar : '#toolbar',
            onLoadSuccess : function() {
                $('#searchForm table').show();
                parent.$.messager.progress('close');
            },
            onRowContextMenu : function(e, rowIndex, rowData) {
                e.preventDefault();
                $(this).datagrid('unselectAll').datagrid('uncheckAll');
                $(this).datagrid('selectRow', rowIndex);
                $('#menu').menu('show', {
                    left : e.pageX,
                    top : e.pageY
                });
            }
        });
    });
</script>
</head>
<body style="padding:0 20px;" >
	<div class="easyui-layout" data-options="fit : true,border : false">
        <div data-options="region:'north',border:false,collapsible:false" id="searchBox">
        	<div class="sLeft">
	            <form id="searchForm">
	            	<input type="text" id="searchName" name="searchName" autocomplete="off" class="sInput" placeholder="输入商品名进行搜索"  onkeydown="if(event.keyCode == 13){ $.fn.dataGridOptions.searchFun('#searchForm');return false;}"/><a href="javascript:;" title="查询" class="sBtn" onclick="$.fn.dataGridOptions.searchFun('#searchForm');">查询</a><a href="javascript:;" class="advBtn" title="条件查询">条件查询 <i class="iconfont">&#xe638;</i></a>
	            	<a href="javascript:void(0);" class="reloadIcon" onclick="dataGrid.datagrid('reload');" title="刷新" ><i class="iconfont">&#xe603;</i></a>
	            </form>
            </div>
            <div class="sRight">
				<a onclick="$.fn.dataGridOptions.addFun(-1,addTitle,winWidth,winHeight,addUrl);" href="javascript:void(0);" class="addBtn"><i class="iconfont">&#xe629;</i>添加</a>
            </div>
            <form id="showAdw">
		        <ul class="showAdw" style="display:none">
		        	<a href="javascript:void(0);"><i class="iconfont closeWin">&#xe628;</i></a>
		        	<li><span>商品名</span><input type="text" name="name" autocomplete="off"/></li>
		       		<li><span>商品类别</span><select name="categoryId" id="type">
						<option value="">全部</option>
		       			<#list goodsCategoryList as item>
		       				<option value="${item.id}">${item.name}</option>
		       			</#list>
					</select></li>
		       		<li><#if need_verify><span>类型</span><#else><span>状态</span></#if><select name="type" id="type">
						<option value="99">全部</option>
						<option value="0">待上架</option>
						<option value="1">已上架</option>
						<option value="-1">已下架</option>
					</select></li>
					<#if need_verify>
		       		<li><span>状态</span><select name="status" id="status">
						<option value="-99">全部</option>
						<option value="0">待审核</option>
						<option value="1">审核通过</option>
						<option value="-1">审核未通过</option>
					</select></li>
					</#if>
		       		<li><span>添加时间</span><input type="text" name="startTime" id="startTime" onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'endTime\')}',readOnly:true})" class="searchTime"/>&nbsp;-&nbsp;<input type="text" name="endTime" id="endTime" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'startTime\')}',readOnly:true})" class="searchTime"/></li>
		       		<li><span>&nbsp;</span><a href="javascript:void(0);" class="searchBtn sureBtn" onclick="$.fn.dataGridOptions.searchFun('#showAdw');">确定</a><a href="javascript:void(0);" class="searchBtn" onclick="$.fn.dataGridOptions.cleanFun('#searchForm');">重置</a></li>
		        </ul>
	        </form>
        </div>
        <div data-options="region:'center'" style="margin-top:30px;padding-bottom:30px;">
            <table id="dataGrid"></table>
        </div>
    </div>
    <script src="${theme_dir}/js/search.js"></script>
</body>
</html>
